package com.ihr360.commons.lang;

import java.net.InetAddress;
import java.net.NetworkInterface;
import java.net.UnknownHostException;
import java.util.ArrayList;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;

public class SystemInfo {
    private static SystemInfo.Os os;
    private static SystemInfo.User user;
    private static SystemInfo.Java java;
    private static SystemInfo.Jvm jvm;
    private static SystemInfo.JavaSpec javaSpec;
    private static SystemInfo.JvmSpec jvmSpec;
    private static SystemInfo.JavaRuntime javaRuntime;
    static final Set<String> usedProperties;

    public SystemInfo() {
    }

    public static String getTmpDir() {
        return System.getProperty("java.io.tmpdir");
    }

    public static Set<String> getUsedproperties() {
        return usedProperties;
    }

    public static SystemInfo.Host getHost() {
        return new SystemInfo.Host();
    }

    public static SystemInfo.Os getOs() {
        return os;
    }

    public static SystemInfo.User getUser() {
        return user;
    }

    public static SystemInfo.Java getJava() {
        return java;
    }

    public static SystemInfo.Jvm getJvm() {
        return jvm;
    }

    public static SystemInfo.JavaSpec getJavaSpec() {
        return javaSpec;
    }

    public static SystemInfo.JvmSpec getJvmSpec() {
        return jvmSpec;
    }

    public static SystemInfo.JavaRuntime getJavaRuntime() {
        return javaRuntime;
    }

    static {
        HashMap origin = new HashMap(System.getProperties());
        Map properties = new HashMap<>(origin);
        os = new SystemInfo.Os(properties);
        user = new SystemInfo.User(properties);
        java = new SystemInfo.Java(properties);
        jvm = new SystemInfo.Jvm(properties);
        javaSpec = new SystemInfo.JavaSpec(properties);
        jvmSpec = new SystemInfo.JvmSpec(properties);
        javaRuntime = new SystemInfo.JavaRuntime(properties);
        origin.keySet().removeAll(properties.keySet());
        usedProperties = new HashSet(origin.keySet());
    }

    public static final class Os {
        final String name;
        final String version;
        final String arch;
        final String fileSeparator;
        final String lineSeparator;
        final String pathSeparator;

        Os(Map<String, String> properties) {
            this.name = (String)properties.remove("os.name");
            this.version = (String)properties.remove("os.version");
            this.arch = (String)properties.remove("os.arch");
            this.fileSeparator = (String)properties.remove("file.separator");
            this.lineSeparator = (String)properties.remove("line.separator");
            this.pathSeparator = (String)properties.remove("path.separator");
        }

        public String getName() {
            return this.name;
        }

        public String getVersion() {
            return this.version;
        }

        public String getArch() {
            return this.arch;
        }

        public String getFileSeparator() {
            return this.fileSeparator;
        }

        public String getLineSeparator() {
            return this.lineSeparator;
        }

        public String getPathSeparator() {
            return this.pathSeparator;
        }
    }

    public static final class Java {
        final String version;
        final String vendor;
        final String vendorUrl;

        Java(Map<String, String> properties) {
            this.version = (String)properties.remove("java.version");
            this.vendor = (String)properties.remove("java.vendor");
            this.vendorUrl = (String)properties.remove("java.vendor.url");
        }

        public String getVersion() {
            return this.version;
        }

        public String getVendor() {
            return this.vendor;
        }

        public String getVendorUrl() {
            return this.vendorUrl;
        }
    }

    public static final class Jvm {
        final String name;
        final String version;
        final String vendor;
        final String info;

        Jvm(Map<String, String> properties) {
            this.name = (String)properties.remove("java.vm.name");
            this.version = (String)properties.remove("java.vm.version");
            this.vendor = (String)properties.remove("java.vm.vendor");
            this.info = (String)properties.remove("java.vm.info");
        }

        public String getName() {
            return this.name;
        }

        public String getVersion() {
            return this.version;
        }

        public String getVendor() {
            return this.vendor;
        }

        public String getInfo() {
            return this.info;
        }
    }

    public static final class JavaSpec {
        final String name;
        final String version;
        final String vendor;

        JavaSpec(Map<String, String> properties) {
            this.name = (String)properties.remove("java.specification.name");
            this.version = (String)properties.remove("java.specification.version");
            this.vendor = (String)properties.remove("java.specification.vendor");
        }

        public String getName() {
            return this.name;
        }

        public String getVersion() {
            return this.version;
        }

        public String getVendor() {
            return this.vendor;
        }
    }

    public static final class JvmSpec {
        final String name;
        final String version;
        final String vendor;

        JvmSpec(Map<String, String> properties) {
            this.name = (String)properties.remove("java.vm.specification.name");
            this.version = (String)properties.remove("java.vm.specification.version");
            this.vendor = (String)properties.remove("java.vm.specification.vendor");
        }

        public String getName() {
            return this.name;
        }

        public String getVersion() {
            return this.version;
        }

        public String getVendor() {
            return this.vendor;
        }
    }

    public static final class JavaRuntime {
        final String name;
        final String version;
        final String home;
        final String extDirs;
        final String endorsedDirs;
        final String classpath;
        final String classVersion;
        final String libraryPath;
        final String tmpDir;
        final String fileEncoding;

        JavaRuntime(Map<String, String> properties) {
            this.name = (String)properties.remove("java.runtime.name");
            this.version = (String)properties.remove("java.runtime.version");
            this.home = (String)properties.remove("java.home");
            this.extDirs = (String)properties.remove("java.ext.dirs");
            this.endorsedDirs = (String)properties.remove("java.endorsed.dirs");
            this.classpath = (String)properties.remove("java.class.path");
            this.classVersion = (String)properties.remove("java.class.version");
            this.libraryPath = (String)properties.remove("java.library.path");
            this.tmpDir = (String)properties.remove("java.io.tmpdir");
            this.fileEncoding = (String)properties.remove("file.encoding");
        }

        public String getName() {
            return this.name;
        }

        public String getVersion() {
            return this.version;
        }

        public String getHome() {
            return this.home;
        }

        public String getExtDirs() {
            return this.extDirs;
        }

        public String getEndorsedDirs() {
            return this.endorsedDirs;
        }

        public String getClasspath() {
            return this.classpath;
        }

        public String getClassVersion() {
            return this.classVersion;
        }

        public String getLibraryPath() {
            return this.libraryPath;
        }

        public String getTmpDir() {
            return this.tmpDir;
        }

        public String getFileEncoding() {
            return this.fileEncoding;
        }
    }

    public static final class User {
        final String name;
        final String home;
        final String language;
        final String country;

        User(Map<String, String> properties) {
            this.name = (String)properties.remove("user.name");
            this.home = (String)properties.remove("user.home");
            this.language = (String)properties.remove("user.language");
            String country = (String)properties.remove("user.country");
            if(null == country) {
                country = (String)properties.remove("user.region");
            }

            this.country = country;
        }

        public String getName() {
            return this.name;
        }

        public String getHome() {
            return this.home;
        }

        public String getLanguage() {
            return this.language;
        }

        public String getCountry() {
            return this.country;
        }
    }

    public static final class Host {
        String hostname;
        final Map<String, List<String>> addresses = new HashMap<>();

        Host() {
            try {
                InetAddress e = InetAddress.getLocalHost();
                this.hostname = e.getHostName();
            } catch (UnknownHostException var6) {
                this.hostname = "localhost";
            }

            try {
                Enumeration e1 = NetworkInterface.getNetworkInterfaces();

                while(e1.hasMoreElements()) {
                    NetworkInterface networkInterface = (NetworkInterface)e1.nextElement();
                    String name = networkInterface.getDisplayName();
                    List addrs = new ArrayList<>();
                    Enumeration e2 = networkInterface.getInetAddresses();

                    while(e2.hasMoreElements()) {
                        addrs.add(((InetAddress)e2.nextElement()).getHostAddress());
                    }

                    this.addresses.put(name, addrs);
                }
            } catch (Exception var7) {
                ;
            }

        }

        public String getHostname() {
            return this.hostname;
        }

        public Map<String, List<String>> getAddresses() {
            return this.addresses;
        }
    }
}